/**
 *
 * @author ace
 * @create 2017/7/27
 */
class CircleMainItemCell extends ComponentEx {


    constructor() {
        super();
        this.skinName = "CircleMainItemCellSkin";
    }

    private head: HeadIcon;
    private lab_nick: eui.Label;
    private lab_state: eui.Label;
    private lab_score: eui.Label;
    btn_kill: eui.Button;
    lab_free: eui.Label;

    yikai: boolean = false;



    childrenCreated() {
        super.childrenCreated();
        this.head.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickHandler, this);
        this.btn_kill.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickHandler, this);
    }

    private clickHandler(e: egret.TouchEvent) {
        switch (e.currentTarget) {
            case this.head:
            case this.btn_kill:

                if (this.btn_kill.visible == false) return;

                if (this.data) {
                    let thiz = this;
                    game.askPanel.showMsg(function (r) {
                        if (r) {
                            gameManager.socketManager.send(33, { roomid: thiz.data.roomid, pos: thiz.data.pos })
                        }
                    }, `是否将玩家【${this.data.nick}】踢出本房间？`);
                }
                break;
        }
    }

    update(state, data: any, roomid: string = null) {
        this.skinState = state;

        this.clean();

        if (data) {
            this.data = data;
            this.data.roomid = roomid;
            this.head.src = data.pic;
            this.lab_nick.text = data.nick;
            this.lab_score.textColor = data.cur > 0 ? 0xdd393b : 0x3c9cde;
        } else {
            switch (state) {
                case "empty":
                    this.skinState = "empty";
                    this.head.src = "nobody";
                    break;
            }
            return;
        }
        switch (state) {
            case 'current':
                this.lab_state.text = data.status == 'online' ? '(在线)' : '(离线)';
                // this.lab_state.textColor = data.status == 'online' ? 0x0B7F4C : 0xEF0216;
                break;
            case 'list':
                this.lab_state.text = data.status == 'online' ? '(在线)' : '(离线)';
                // this.lab_state.textColor = data.status == 'online' ? 0x65ffe4 : 0xfffe84;
                break;
            case 'history':
                this.lab_score.text = '' + data.cur;
                //this.lab_score.textColor = data.cur >= 0 ? 0x00bb00 : 0xff0000;
                break;
            case 'details':
                this.lab_score.text = '' + data.cur;
                //this.lab_score.textColor = data.cur >= 0 ? 0x00bb00 : 0xff0000;
                break;

        }
    }
    clean() {
        this.head.src = '';
        this.lab_nick.text = '';
        this.lab_state.text = '';
        this.lab_score.text = '';
        this.btn_kill.visible = false;
    }

    set roomStatus(va: string) {

        if (!this.data) return;
        switch (va) {
            case 'wait':
                this.btn_kill.visible = <boolean>Circle.circle_data.ifown;
                break;
            case 'start':
                this.btn_kill.visible = false;
                break;
        }
    }

    set showKill(boo: boolean) {

        this.btn_kill.visible = boo;
    }

    public lock(flag: boolean) {
        if (flag) {
            this.skinState = "lock";
        }

    }
}